<template>
	<view class="page">
		<template v-if="isLogin">
			<view class="category-list row-2">
				<navigator url="/package_shibie/dataList/dataList" open-type="navigate" hover-class="none" class="item">
					<view class="icon">
						<image src="@/static/images/ysb_datas.png" mode="widthFix"></image>
					</view>
					<view class="text">识别记录</view>
				</navigator>
				<!-- <navigator url="/package_yunpeixun/dataList/dataList" open-type="navigate" hover-class="none" class="item">
					<view class="icon"><image src="@/static/images/export.png" mode="widthFix"></image></view>
					<view class="text">培训数据</view>
				</navigator> -->
			</view>
			<view class="start-btn-area">
				<view class="btn" @click="showActionSheet(1)">
					<image src="@/static/images/cqsb.png" mode="widthFix"></image>
				</view>
				<!-- <view class="btn" @click="flag.isFullPage=true;flag.isChangeType=true">
					<image src="@/static/images/yc_start.png" mode="widthFix"></image>
				</view> -->
			</view>


			<view v-if="flag.isFullPage" class="full-fix-page">
				<view v-if="flag.isChangeType" class="bottom-tab-btn a-fadeinB">
					<view class="bottom-lay-btn-wrap m-b2">
						<view class="lay-btn" @click="checkPhoto">从相册选择</view>
						<navigator url="/package_shibie/camera/camera" hover-class="none" class="lay-btn">拍照</navigator>
					</view>
					<view class="bottom-lay-btn-wrap m-b2" @click="flag.isFullPage=false;flag.isChangeType=false">
						<view class="lay-btn">取消</view>
					</view>
				</view>
			</view>

		</template>
	</view>
</template>

<script>
	import { HTTP_OLD_HOST, WEB_HOST, appid, appsecret } from '@/config.js'
	import { dateFormat, uploadImage, uploadToServe, } from '@/common/util.js'
	export default {
		name: 'name',
		data() {
			return {
				isLogin: false,
				userInfo: uni.getStorageSync('userInfo'),
				token: uni.getStorageSync('token'),
				appid: appid,
				appsecret: appsecret,
				loginStateUpdate: false,
				app_name: getApp().globalData.app_name,
				files: [],
				flag: {
					isFullPage: false,
					isChangeType: false
				},
			}


		},
		async onLoad() {
			this.isLogin = await this.$loginState('check');
		},
		async onShow() {

		},
		onUnload() {
			this.flag.isFullPage = false;
			this.flag.isChangeType = false
		},
		onHide() {
			this.flag.isFullPage = false;
			this.flag.isChangeType = false
		},
		methods: {

			showActionSheet(t, type) {
				console.log('type', type);
				if (t == 1) {
					uni.showActionSheet({
						itemList: ['虫情识别', '苗情识别'],
						success: res => {
							console.log(res.tapIndex);
							// if (res.tapIndex == 0) {
							// this.checkPhoto();
							// } else if (res.tapIndex == 1) {
							// uni.navigateTo({
							// 	url: '/package_shibie/camera/camera'
							// })
							// }
							this.showActionSheet(2, +res.tapIndex + 1);
						}
					})
				}

				if (t == 2) {
					this.checkPhoto(type)

					// uni.chooseImage({
					//     count: count, //默认9
					//     sizeType: ['original','compressed'], //可以指定是原图还是压缩图，默认二者都有
					//     sourceType: ['album','camera'], //从相册选择
					//     success: function (res){   
					// 		return callback(res.tempFilePaths); 
					//     }
					// });

					// uni.showActionSheet({
					// 	itemList: ['从相册选择', '拍照', '返回'],
					// 	success: res => {
					// 		console.log(res.tapIndex);
					// 			this.checkPhoto(type);
					// 		if (res.tapIndex == 0) {
					// 		} else if (res.tapIndex == 1) {
					// 			uni.navigateTo({
					// 				url: `/package_shibie/camera/camera?type=${type}`
					// 			})
					// 		} else if (res.tapIndex == 2) {
					// 			this.showActionSheet(1);
					// 		}
					// 	}
					// })
				}
			},
			checkPhoto: async function(type) {
				let _this = this;
				let params = {
					appid: _this.appid,
					token: _this.token,
					uid: _this.userInfo.uid,
					type
				}
				console.log('upload-params', params);
				// 上传现场照片
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album','camera'], //从相册选择
					success: function(res) {
						console.log(JSON.stringify(res.tempFilePaths));
						uploadToServe({
							type: 1,
							url: 'https://wxapi.agri120.org/user/sb-insert.do',
							filePath: res.tempFilePaths[0],
							name: 'myfile',
							formData: params
						}).then((up_res) => {
							console.log('up_res', up_res);
							uni.hideLoading();
							if (up_res.ret == 1000) {
								uni.navigateTo({
									url: `/package_shibie/dataList/dataList?type=${type}`
								})
							}
						})
					}
				});

			},

			// 打开弹窗
			showPopup: function(t, n) {
				if (t == 'show') {
					this.flag.isFullPage = true;
					this.flag[n] = true;
				} else if (t == 'hide') {
					for (let i in this.flag) {
						this.flag[i] = false;
					}
				}
			},

		},
		components: {

		},

		computed: {

		},
		watch: {

		}

	}
</script>

<style lang="less" scoped>
	.category-list {
		background: #fff;
		margin-bottom: 20rpx;
		padding: 20rpx;
		display: flex;
		// justify-content: center;
		box-sizing: border-box;

		.item {
			display: flex;
			// justify-content: center;
			flex-direction: column;
			align-items: center;
			font-size: 28rpx;

			.icon {
				width: 30% !important;
			}
		}
	}

	.row-2 {
		justify-content: center;
	}

	.row-2 .item {
		width: 48%;
	}

	.name {
		text-align: center;

		text {
			padding-top: 10rpx;
			border-top: 2rpx dashed #999;
			font-size: 28rpx;
			color: #999;
		}
	}

	.start-btn-area {
		position: absolute;
		left: 0;
		bottom: 150rpx;
		width: 100%;
	}

	.btn {
		width: 60%;
		margin: 0 auto;

		image {
			width: 100%;
		}
	}

	.check-photo {
		text-align: center;
		font-size: 28rpx;
	}
</style>